package com.account.filter;

import com.account.dao.AccountDao;
import com.account.entity.Account;
import org.springframework.core.annotation.Order;

import javax.annotation.Resource;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: lixiao
 * Created Date: 2020/4/9 22:51
 */
@Order(1)
@WebFilter(filterName = "testFilter",urlPatterns = "/*")
public class TestFilter implements Filter {


    @Resource(name = "accountDao")
    private AccountDao accountDao;

    @Override
    public void init(javax.servlet.FilterConfig filterConfig) throws ServletException {
        Account user = accountDao.findAccount(111);
        System.out.println("进入过滤器");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("过滤器进入doFilter");
        Map<String, String[]> params = request.getParameterMap();
        for(String key:params.keySet()){
            if(params.get(key).length>0){
                for(String var:params.get(key)){
                    System.out.println(var);
                }
            }
        }
        chain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}